package org.blogwu.learn.jvmlearn.class1.class20;

import org.blogwu.learn.jvmlearn.class1.MyTest16;

/**
 * 关于命名空间的重要说明
 * 1. 子加载器所加载的类能够访问父加载器所加载的类
 * 2. 父加载器所加载的类无法访问到子加载器所加载的类.
 */


public class MyTest17_1 {

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        MyTest16 loader1 = new MyTest16("loader1");
        loader1.setPath("D:\\temp\\");
        Class<?> cls1 = loader1.loadClass("org.blogwu.learn.jvmlearn.class1.class19.MySample");
        System.out.println("class hashcode:" + cls1.hashCode());
        System.out.println("class classloader:" + cls1.getClassLoader());

        //当删除MyCat.class时,会爆出NoClassDefFoundError异常,因为加载MyCat是由加载MySample的加载器来加载的,
        //MySample.class时,  加载Mycat会由加载MySample的类加载器来加载,但是由于双亲委托加载,还是会委托父加载器,而且classpath里还是有MyCat.class  ,所以还是由父类来加载
        Object o1 = cls1.newInstance();
        System.out.println(o1.getClass());


    }
}
